package com.yuchao.springboot.handler;

import com.yuchao.springboot.utils.BeanTool;

import java.util.Map;

/**
 * @description:
 * @author: xingyuchao
 * @date: 2019-11-08
 */
public class HandlerContext{

    private Map<String,Class> handlerMap;


    public HandlerContext(Map<String, Class> handlerMap) {
        this.handlerMap = handlerMap;
    }

    public AbstractHandler getInstance(String type){

        Class clazz = handlerMap.get(type);

        if(clazz == null){
            throw new IllegalArgumentException("not found handler for type: " + type);
        }

        return  (AbstractHandler) BeanTool.getBean(clazz);
    }

}
